package com.ems.mapper;

import com.ems.entity.StationEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ems.vo.StationVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 储能电站 Mapper 接口
 * </p>
 *
 * @author WuZH
 * @since 2023-10-24
 */
@Mapper
public interface StationMapper extends BaseMapper<StationEntity> {

    @Select ( value = "<script>SELECT * FROM station_info si " +
            "<trim prefix=\"where\" prefixOverrides=\"and | or\">" +
            "<if test='stationVo.stationName!=null'> AND si.stationName LIKE CONCAT('%', #{stationVo.stationName, jdbcType=VARCHAR}, '%') </if>" +
            "<if test='stationVo.merchantId!=null'> AND si.merchantId=#{stationVo.merchantId}</if> " +
            " AND si.isUsed=1</trim> ORDER BY si.createTime DESC LIMIT #{stationVo.page}, #{stationVo.limit}</script>" )
    List<StationVo> queryList ( @Param ( "stationVo" ) StationVo stationVo );

    @Select ( value = "<script>SELECT COUNT(1) FROM station_info si " +
            "<trim prefix=\"where\" prefixOverrides=\"and | or\">" +
            "<if test='stationVo.stationName!=null'> AND si.stationName LIKE CONCAT('%', #{stationVo.stationName, jdbcType=VARCHAR}, '%') </if>" +
            "<if test='stationVo.merchantId!=null'> AND si.merchantId=#{stationVo.merchantId}</if> " +
            "AND si.isUsed=1</trim></script>" )
    Integer queryCount ( @Param ( "stationVo" ) StationVo stationVo );

}
